package com.wc.算法提高课.B第二章_搜索.Flood_Fill.山峰和山谷;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/23 17:43
 * @description https://www.acwing.com/problem/content/1108/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, M = N * N;
    static int[][] h = new int[N][N];
    static int[] q = new int[M];
    static boolean[][] st = new boolean[N][N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++) {
                h[i][j] = sc.nextInt();
            }
        int peak = 0, valley = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (!st[i][j]) {
                    boolean[] higher = new boolean[1], lower = new boolean[1];
                    bfs(i, j, higher, lower);
                    if (!higher[0]) peak++;
                    if (!lower[0]) valley++;
                }
            }
        }
        out.println(peak + " " + valley);
        out.flush();
    }


    static void bfs(int sx, int sy, boolean[] higher, boolean[] lower) {
        int hh = 0, tt = 0;
        q[0] = sx * N + sy;
        st[sx][sy] = true;
        while (hh <= tt) {
            int x = q[hh] / N, y = q[hh++] % N;
            for (int i = x - 1; i <= x + 1; i++) {
                for (int j = y - 1; j <= y + 1; j++) {
                    if (i < 0 || i >= n || j < 0 || j >= n) continue;
                    if (h[i][j] != h[x][y]) {
                        if (h[i][j] < h[x][y]) lower[0] = true;
                        else {
                            higher[0] = true;
                        }
                    } else if (!st[i][j]) {
                        q[++tt] = i * N + j;
                        st[i][j] = true;
                    }
                }
            }
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
